package 二叉树;
//https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/
public class _104_二叉树的最大深度 {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    public int maxDepth(TreeNode root) {
        if (root == null) return 0;
        //最大深度是树的左右子树的深度最大值加1
        return Math.max(maxDepth(root.left),maxDepth(root.right))+1;
    }
}
